package com.lxl.bt.adapter;

import android.os.Parcelable;
import android.util.Log;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.lxl.bt.fragment.BTCListFragment;


public class BTCFragmentAdapter extends FragmentStatePagerAdapter {
    private static String TAG = "SelectionFragmentAdapter";
    private String[] incomeTypes;
    private String coinName;
    private String[] titles;

    public BTCFragmentAdapter(FragmentManager fm, String[] titles, String[] incomeTypes, String coinName) {
        this(fm, titles);
        this.coinName = coinName;
        this.incomeTypes = incomeTypes;
    }

    public BTCFragmentAdapter(FragmentManager supportFragmentManager, String[] titles) {
        super(supportFragmentManager);
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return BTCListFragment.newInstance(titles[position], incomeTypes[position], coinName);
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    @Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        // super.restoreState(state, loader);
        //重写这个方法是为了防止在restoreState的时候导致应用崩溃，这样做虽然不太好，但是目前我也只能想到这种方法了
        Log.i(TAG, "restoreState");
    }
}
